﻿/*********************************************************
 * copyright learnren.com 版权所有
 * 开发人员：minyuan
 * 创建时间：2013/6/24 0:18:41
 * 描述说明：
 * 
 * 更改历史：
 * 
 * *******************************************************/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LEARNREN.COM.UI;
using LEARNREN.COM.Entity;
using LEARNREN.COM.BLL;
using LEARNREN.COM.Entity.Enum;

namespace LEARNREN.COM.WebSite
{
    public partial class ProductList : BasePage
    {
        protected IEnumerable<Catalogue> productCatalogueList = null;
        protected IEnumerable<Catalogue> childCatalogueList = null;
        protected Catalogue curentCatalogue = null;
        protected List<Product> productList = null;

        private ProductLogic productLogic = null;
        private CatalogueLogic catalogueLogic = null;

        protected void Page_Load(object sender, EventArgs e)
        {
             Initialize();
        }

        private void Initialize()
        {
            productCatalogueList = catalogueLogic.GetConfigedProductCatalogueCollection();

            string sid = Request.QueryString["id"];
            long id = 0;
            if (long.TryParse(sid, out id))
            {
                childCatalogueList = catalogueLogic.GetChildren(id);
                curentCatalogue = catalogueLogic.GetByIdFromCache(id);
                if (curentCatalogue == null)
                {
                    Response.Redirect("~/");
                }
                if (curentCatalogue.ParentId == 0)
                {
                    productList = productLogic.GetListDESC(p => p.ParentPath.StartsWith(curentCatalogue.Path), p => p.Id);

                }
                else
                {
                    productList = productLogic.GetListDESC(p => p.CatalogueId == curentCatalogue.Id, p => p.Id);
                }
            }
            else
            {
                Response.Redirect("~/");
            }
        }

        protected override void InitLogic()
        {
            productLogic = new ProductLogic();
            catalogueLogic = new CatalogueLogic();
        }

        protected override void DisposeLogic()
        {
            if (productLogic != null)
            {
                productLogic.Dispose();
                productLogic = null;
            }

            if (catalogueLogic != null)
            {
                catalogueLogic.Dispose();
                catalogueLogic = null;
            }
        }
    }
}